﻿using RulesEngine.Event;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace RulesEngine.Rule
{
    public enum State { Common, Triggerd, Warning, Recovered };
    //规则
    public abstract class BaseRule : IRule

    {
        private object ruleObject;
        private string ruleName;       
                                 

        protected abstract Boolean chargeState(State state);  
     
        protected virtual void onTrigger()
        {
            RuleEventArgs eventArgs = new RuleEventArgs();
            eventArgs.State = State.Triggerd;
            RuleEventsHandler(this, eventArgs);       

        }

        protected virtual void onRecovery()
        {
            RuleEventArgs eventArgs = new RuleEventArgs();
            eventArgs.State = State.Recovered;
            RuleEventsHandler(this, eventArgs);
        }

        public event RuleEventHandler<RuleEventArgs> RuleEventsHandler;


        public abstract void run();
        public object RuleObject { get => ruleObject; set => ruleObject = value; }
        public string RuleName { get => ruleName; set => ruleName = value; }

    }
}
